import { createStore } from 'vuex'

export default createStore({
  state: {
    loginUser:{
      loginName:localStorage.getItem('user')?JSON.parse(localStorage.getItem('user') as string).name: '',
    }
  },
  mutations: {
    login(state,info){
       state.loginUser.loginName=info.name
       localStorage.setItem('user',JSON.stringify(info))
    },
    logout(state){
      state.loginUser.loginName=''
      localStorage.removeItem('user')
    }
  },
  actions: {
    login({commit},info){
      commit('login',info)
    },
    logout({commit}){
      commit('logout')
    }
  },

  modules: {
  }
})
